package ${packageBase}.${tableBean.tableNameNoDash}.action;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.context.annotation.Scope;
import org.springframework.ui.Model;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;

import ${packageBase}.${tableBean.tableNameNoDash}.entity.${tableBean.tableNameCapitalized}Entity;
import ${packageBase}.${tableBean.tableNameNoDash}.service.${tableBean.tableNameCapitalized}Service;
import com.ristone.platform.comm.BaseAction;
import com.ristone.platform.comm.ActionResultMap;

@Controller
@Scope("prototype")
@RequestMapping("/${tableBean.tableNameNoDash}")
public class ${tableBean.tableNameCapitalized}Action extends BaseAction{
	@Autowired
	private ${tableBean.tableNameCapitalized}Service ${tableBean.tableNameNoDash}Service;
	/*
	*表单页面
	*/
	@RequestMapping("form")
	public String addForm(Long id,Model model) {
		if(null!=id){
			${tableBean.tableNameCapitalized}Entity ${tableBean.tableNameNoDash}= ${tableBean.tableNameNoDash}Service.get(id);
			model.addAttribute("bean", ${tableBean.tableNameNoDash});
		}
		return "${tableBean.tableNameNoDash}/web/form";
	}
	/*
	*保存
	*/
	@RequestMapping("save")
	public String save(${tableBean.tableNameCapitalized}Entity ${tableBean.tableNameNoDash},Model model){
		try {
			${tableBean.tableNameNoDash}Service.save(${tableBean.tableNameNoDash});
			resultMap.setSuccess(true);
		} catch (Exception e) {
			resultMap.setSuccess(false);
			resultMap.setMsg("保存失败");
		}
		return "redirect:list";
	}
	/**
	 * 列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping("list")
	public String list(Model model){
		/*
		resultMap.setSuccess(true);
		List<${tableBean.tableNameCapitalized}Entity> list = ${tableBean.tableNameNoDash}Service.getAll();
		resultMap.setData(list);
		model.addAttribute(_RESULTMAP,resultMap);
		*/
		return "${tableBean.tableNameNoDash}/web/list";
	}
	/**
	 * 分布查询数据
	 * @param page
	 * @return
	 */
	@ResponseBody
	@RequestMapping("pageList")
	public Page<${tableBean.tableNameCapitalized}Entity> listPage(Pageable pageable){
		return  ${tableBean.tableNameNoDash}Service.getListOfPage(pageable);
	}
	/**
	 * 删除
	 * @param dream
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("del")
	public ActionResultMap del(Long id){
		${tableBean.tableNameNoDash}Service.delete(id);
		resultMap.setMsg("删除成功！");
		return resultMap;
	}
}
